﻿using Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DS
{
    public partial class CommandsForm : DSkin.Forms.Skin_VS_Dark
    {
        public CommandsForm()
        {
            InitializeComponent();
        }
        
        public List<string> selectedCommands;

        private List<string> commandslist;
        private void CommandsForm_Load(object sender, EventArgs e)
        {
            #region 从配置文件初始化commandslist
            commandslist = new List<string>();
            selectedCommands = new List<string>();
            string path = AppDomain.CurrentDomain.BaseDirectory;
            if (!path.EndsWith(@"\"))
                path += @"\";
            string inifilename = "commands.ini";
            string iniFile = path + inifilename;

            if (File.Exists(iniFile))
            {
                Common.IniFile ini = new Common.IniFile(iniFile);

                int ItemCount;
                Int32.TryParse(ini.IniReadValue("CommandCount", "ItemCount"), out ItemCount);

                for (int i = 0; i < ItemCount; i++)
                {
                    StringBuilder commandstr = new StringBuilder("commandItem");
                    commandstr.Append(i);
                    commandslist.Add(ini.IniReadValue("CommandItem", commandstr.ToString()));
                }
            }
            else
            {
                Log.Error("commands.ini" + "配置文件不存在");
            }
            #endregion

            foreach (string command in commandslist)
            {
                DS.Controls.CommandsItem commandsItem = new Controls.CommandsItem();
                commandsItem.duiTextBox1.Text = command;
                this.dSkinListBox1.Items.Add(commandsItem);
            }
        }

        private void dSkinButton1_Click(object sender, EventArgs e)
        {
            foreach (DS.Controls.CommandsItem item in this.dSkinListBox1.Items)
            {
                if (item.duiCheckBox1.Checked)
                {
                    selectedCommands.Add(item.duiTextBox1.Text);
                }
            }
            this.Close();
        }
    }
}
